import 'dart:convert';

import 'package:du_application/http/HttpUtil.dart';
import 'package:du_application/model/ListModel.dart';
import 'package:flutter/material.dart';

class ListProvider with ChangeNotifier {
 
ListModel model;



  getList({id,keyword}) async {
        if(id!=null){
             await  HttpUtil.getInstance().get("/goods/list?categoryId=${id}").then((data){
   model = ListModel.fromJson(json.decode(data.toString()));
         
         
   });

   }else{
     await  HttpUtil.getInstance().get("/goods/list?keyword=${keyword}").then((data){
     model = ListModel.fromJson(json.decode(data.toString()));
   });  
 
   }
notifyListeners();
  }

  void getNext({id,keyword})async {
    try{
      if(id!=null){
 await  HttpUtil.getInstance().get("/goods/list?categoryId=${id}&offset=${model.data.page+1}").then((data){
   model.data.firstList.addAll(ListModel.fromJson(json.decode(data.toString())).data.firstList) ;
   });
      }
     if(keyword!=null){
        await  HttpUtil.getInstance().get("/goods/list?keyword=${keyword}&offset=${model.data.page+1}").then((data){
   model.data.firstList.addAll(ListModel.fromJson(json.decode(data.toString())).data.firstList) ;
   });
     }
   notifyListeners();
    }catch(e){
    throw e;
    }



  }
}